//
//  NSString+Util.m
//  FiveHealth
//
//  Created by WKC on 2018/3/27.
//  Copyright © 2018年 com.wukangcheng.fivehealths. All rights reserved.
//

#import "NSString+Util.h"

@implementation NSString (Util)

- (float)getValue4HeightWithWid:(float)labelWid andFont:(UIFont *)font
{
    CGRect rect = [self boundingRectWithSize:CGSizeMake(labelWid, MAXFLOAT)
                                     options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading
                                  attributes:@{NSFontAttributeName : font} context:nil];
    return rect.size.height;
}
- (float)getValue4WidWithHeight:(float)labelHeight andFont:(UIFont *)font
{
    CGRect rect = [self boundingRectWithSize:CGSizeMake(MAXFLOAT, labelHeight)
                                     options:NSStringDrawingUsesLineFragmentOrigin
                                  attributes:@{NSFontAttributeName : font} context:nil];
    return rect.size.width;
}

- (float)attrGetValue4HeightWithWid:(float)labelWid andFont:(UIFont *)font andLineSpace:(NSMutableParagraphStyle *)paragraphStyle {
    
    CGRect rect = [self boundingRectWithSize:CGSizeMake(labelWid, MAXFLOAT)
                                     options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading
                                  attributes:@{NSFontAttributeName : font,
                                               NSParagraphStyleAttributeName : paragraphStyle} context:nil];
    return rect.size.height;
}

- (NSString *)getFormateDateString
{
    if (self.length==0) {
        return self;
    }
    // timeStampString 是服务器返回的13位时间戳
    NSString *timeStampString  = self;
    // iOS 生成的时间戳是10位
    NSTimeInterval interval    =[timeStampString doubleValue] / 1000.0;
    NSDate *date               = [NSDate dateWithTimeIntervalSince1970:interval];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString *dateString = [formatter stringFromDate: date];
    return dateString;
}

@end
